package com.tocea.formation.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name= "Person")
public class Person implements Serializable{
	
	private static final long serialVersionUID = -6273580796367259665L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String nom;
	private String prenom;
	
	@OneToMany
    private Set<Event> events;
	@ManyToMany
	private Set<Event> visibleEvents;
	
	public Person(){
		events= new HashSet<Event>();
		visibleEvents= new HashSet<Event>();
	}
	
	public Person(Integer _id, String _nom, String _prenom){
		this();
		this.id = _id;
		this.nom = _nom;
		this.prenom = _prenom;
	}
	
	public Event createEvent(Integer _id, String _nom){
		Event e= new Event(_id, _nom, this);
		events.add(e);
		return e;
	}
	
	public boolean removeEvent(Event e){
		return events.remove(e);
	}
	
	public boolean addVisibleEvents(Event e){
		return visibleEvents.add(e);
	}
	
	public boolean removeVisibleEvents(Event e){
		return visibleEvents.remove(e);
	}
	
	public Set<Event> getVisibleEvents() {
		return visibleEvents;
	}

	public void setVisibleEvents(Set<Event> visibleEvents) {
		this.visibleEvents = visibleEvents;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public Set<Event> getEvents() {
		return events;
	}

	public void setEvents(Set<Event> events) {
		this.events = events;
	}

	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((nom == null) ? 0 : nom.hashCode());
		result = prime * result + ((prenom == null) ? 0 : prenom.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (nom == null) {
			if (other.nom != null)
				return false;
		} else if (!nom.equals(other.nom))
			return false;
		if (prenom == null) {
			if (other.prenom != null)
				return false;
		} else if (!prenom.equals(other.prenom))
			return false;
		return true;
	}
	

}
